﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Serialization;
using ElectronicCommerce.Framework.Collections;

namespace ElectronicCommerce.Framework.Diagnostics
{
    /// <summary>
    /// 扩展属性。
    /// </summary>
    [Serializable]
    [XmlRoot("ExtendedProperty")]
    [DataContract]
    public class ExtendedProperty : IKeyedObject
    {
        #region [ Fields ]

        private string name;
        private string value;
        private ExtendedPropertyCollection subExtendedProperties;

        #endregion

        #region [ Constructors ]

        /// <summary>
        /// 
        /// </summary>
        public ExtendedProperty()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public ExtendedProperty(string name, string value)
        {
            this.name = name;
            this.value = value;
        }

        #endregion

        #region [ Properties ]

        /// <summary>
        /// 键值。
        /// </summary>
        public string Key
        {
            get { return this.name; }
        }

        /// <summary>
        /// 属性名。
        /// </summary>
        [XmlAttribute("name")]
        [DataMember]
        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        /// <summary>
        /// 属性值。
        /// </summary>
        [XmlAttribute("value")]
        [DataMember]
        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        /// <summary>
        /// 子扩展属性集合。
        /// </summary>
        [XmlArray("SubExtendedProperties")]
        [XmlArrayItem("ExtendedProperty")]
        [DataMember]
        public ExtendedPropertyCollection SubExtendedProperties
        {
            get { return this.subExtendedProperties; }
            set { this.subExtendedProperties = value; }
        }

        #endregion
    }
}
